<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      :model="queryParams"
      inline
      ref="queryForm"
      size="small"
      label-width="68px"
    >
      <el-form-item label="委托单位" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入委托单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">
          搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" style="width: 100%">
      <el-table-column type="index" label="序号" width="120" align="center" />
      <el-table-column prop="customerName" label="委托单位" align="center" />
      <el-table-column prop="projectCount" label="项目数量" align="center" />
      <el-table-column prop="buildingCount" label="建筑构造物数量" align="center" />
      <el-table-column prop="address" label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row.customerId)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <Detail v-if="detailShow" ref="Detail" @refreshDetail="refreshDetail" />
  </div>
</template>

<script>
import { getProjectCountAndBuildingCountList } from "@/api/plan-produce/task";
import Detail from "./indexInfo.vue";

export default {
  name: "Task-index",
  components: { Detail },
  data() {
    return {
      loading: false, // 遮罩层
      showSearch: true, // 显示搜索条件
      total: 0, // 总条数
      dataList: [], // 数据列表
      detailShow: false,// 详情页面
      // 查询参数
      queryParams: {
        customerName: null,
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  mounted() {
    let query = this.$route.query;
    if (query.customerId) {
      this.handleDetail(query.customerId);
    }
    this.getList();
  },

  methods: {
    getList() {
      this.loading = true;
      getProjectCountAndBuildingCountList(this.queryParams).then((res) => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 跳转详情
    handleDetail(id) {
      this.detailShow = true;
      this.$nextTick(() => {
        this.$refs.Detail.init(id);
      });
    },
    // 回调
    refreshDetail(list) {
      this.detailShow = false;
      setTimeout(() => {
        this.$nextTick(() => {
          this.$refs.taskDetail.init(list);
        });
      }, 0);
    },
  },
};
</script>
<style lang="scss" scoped>
.mapSty {
  width: 100%;
  height: 450px;
  position: relative;
}

#allMap {
  width: 100%;
  height: 450px;
}

.textSty {
  font-size: 14px;
  color: rgb(102, 102, 102);
}

.textIconSty {
  margin-left: 10px;
  font-size: 12px;
  color: rgb(102, 102, 102);
  margin-right: 0.3rem;

  .listIcon {
    padding: 0 5px;
  }
}

.text-with-line {
  text-decoration: line-through;
}

::v-deep .el-card__body {
  padding: 0;
}
</style>
